package Math;

public class _258_AddDigits {

    //over time limited
    public int addDigits0(int num) {
        int div = 1;
        int result = num;
        while (result >= 10) {
            while (div <= result / 10) {
                div*=10;
            }
            int sum = 0;
            int temp = result;
            while (div != 0) {
                System.out.println("dd");
                sum+=temp/div;
                temp = temp%div;
                div/=10;
            }
            result = sum;
        }
        return result;
    }

    public int addDitgits(int num) {
        return 1+(num-1)%9;
    }

    //reference quicker solution
    public int addDigits1(int num) {
        while (num >= 10) {
            num = num /10 + num % 10;
        }
        return num;
    }
}
